const BASE_URL ="http://123.207.32.32:9001"

const token = wx.getStorageInfoSync("token_key")
const LOGIN_BASE_URL = "http://123.207.32.32:3000"
class LTRequest{
    constructor(baseurl,authHeader={}){
         this.baseurl = baseurl
         this.authHeader = authHeader
    }
   request(url,method,params,isAuth=false,header={}){
       const finalHeader = isAuth?{...this.authHeader,...header}:header
       return new Promise((resolve,reject)=>{
           wx.request({
             url: this.baseurl+url,
             method:method,
             data:params,
             header:finalHeader,
             success:function(res){
                 resolve(res.data)
             },
             fail:reject
           })
       })
   }
   get(url,params,isAuth=false,header){
    return this.request(url,"GET",params,isAuth,header)
   }
   post(url,params,isAuth=false,header){
    return this.request(url,"POST",params,isAuth,header)
   }
}
const ltRequest = new LTRequest(BASE_URL)
const loginRequest = new LTRequest(LOGIN_BASE_URL,token)

export default ltRequest
export {
    loginRequest
}
